package com.bizfx.component
{
	import com.bizfx.utils.StringUtils;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	import mx.events.FlexEvent;
	
	import org.springextensions.actionscript.context.metadata.ClassScannerObjectFactoryPostProcessor;
	import org.springextensions.actionscript.context.support.FlexXMLApplicationContext;
	
	public class BizApplication extends BaseBizApplication
	{
		private static var _instance:BizApplication;
		
		public static function get instance(): BizApplication
		{
			return _instance;
		}
		
		private var _applicationContextPath:String = "configs/application-context.xml";
		/**
		 * 应用配置路径
		 */
		public function get applicationContextPath(): String
		{
			return _applicationContextPath;  
		}
		
		public function set applicationContextPath(value: String):void
		{
			_applicationContextPath = value;  
		} 
		
		private var context:FlexXMLApplicationContext;
		
		public function BizApplication()
		{
			super();
			_instance = this;
			this.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
		}
		
		private function creationCompleteHandler(event:FlexEvent):void
		{
			this.removeEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
			context = new FlexXMLApplicationContext(applicationContextPath);//创建一个IoC容器
			context.addEventListener(Event.COMPLETE, contextLoadCompletedHandler);//添加事件侦听器，侦听完成事件，执行回调
			context.addObjectFactoryPostProcessor(new ClassScannerObjectFactoryPostProcessor());
			context.load();//加载配置文件
		}
		
		private function contextLoadCompletedHandler(e:Event):void {
			context.removeEventListener(Event.COMPLETE, contextLoadCompletedHandler);//添加事件侦听器，侦听完成事件，执行回调
		}
	}
}